package eleme.openapi.sdk.api.service;

import eleme.openapi.sdk.api.annotation.Service;
import eleme.openapi.sdk.api.base.BaseNopService;
import eleme.openapi.sdk.api.exception.ServiceException;
import eleme.openapi.sdk.oauth.response.Token;
import eleme.openapi.sdk.config.Config;
import eleme.openapi.sdk.api.entity.shop.*;
import eleme.openapi.sdk.api.enumeration.shop.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

/**
 * 店铺服务
 */
@Service("eleme.shop")
public class ShopService extends BaseNopService {
    public ShopService(Config config,Token token) {
        super(config, token, ShopService.class);
    }

    /**
     * 查询店铺信息
     *
     * @param shopId 店铺Id
     * @return 店铺
     * @throws ServiceException 服务异常
     */
    public OShop getShop(long shopId) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("shopId", shopId);
        return call("eleme.shop.getShop", params);
    }

    /**
     * 更新店铺基本信息
     *
     * @param shopId 店铺Id
     * @param properties 店铺属性
     * @return 店铺
     * @throws ServiceException 服务异常
     */
    public OShop updateShop(long shopId, Map<OShopProperty,Object> properties) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("shopId", shopId);
        params.put("properties", properties);
        return call("eleme.shop.updateShop", params);
    }

    /**
     * 批量获取店铺简要
     *
     * @param shopIds 店铺Id的列表
     * @return 店铺简要列表
     * @throws ServiceException 服务异常
     */
    public Map<Long,OSimpleShop> mgetShopStatus(List<Long> shopIds) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("shopIds", shopIds);
        return call("eleme.shop.mgetShopStatus", params);
    }

    /**
     * 设置送达时间
     *
     * @param shopId 店铺Id
     * @param deliveryBasicMins 配送基准时间(单位分钟)
     * @param deliveryAdjustMins 配送调整时间(单位分钟)
     * @throws ServiceException 服务异常
     */
    public void setDeliveryTime(long shopId, int deliveryBasicMins, int deliveryAdjustMins) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("shopId", shopId);
        params.put("deliveryBasicMins", deliveryBasicMins);
        params.put("deliveryAdjustMins", deliveryAdjustMins);
        call("eleme.shop.setDeliveryTime", params);
    }

    /**
     * 设置是否支持在线退单
     *
     * @param shopId 店铺Id
     * @param enable 是否支持
     * @throws ServiceException 服务异常
     */
    public void setOnlineRefund(long shopId, boolean enable) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("shopId", shopId);
        params.put("enable", enable);
        call("eleme.shop.setOnlineRefund", params);
    }

    /**
     * 设置是否支持预定单及预定天数
     *
     * @param shopId 店铺id
     * @param enabled 是否支持预订
     * @param maxBookingDays 最大预定天数
     * @throws ServiceException 服务异常
     */
    public void setBookingStatus(long shopId, boolean enabled, Integer maxBookingDays) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("shopId", shopId);
        params.put("enabled", enabled);
        params.put("maxBookingDays", maxBookingDays);
        call("eleme.shop.setBookingStatus", params);
    }

    /**
     * 批量通过店铺Id获取Oid
     *
     * @param shopIds 店铺Id的列表
     * @return 店铺id,oid映射列表
     * @throws ServiceException 服务异常
     */
    public Map<Long,Long> getOidByShopIds(List<Long> shopIds) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("shopIds", shopIds);
        return call("eleme.shop.getOidByShopIds", params);
    }

    /**
     * 更新店铺营业时间预设置
     *
     * @param shopId 店铺id
     * @param weekSetting 一周营业时间预设置, 参考 OShopBusyLevelSetting weekSetting 字段定义 
     * @param dateSetting 特定日期营业时间预设置, 参考 OShopBusyLevelSetting dateSetting 字段定义 
     * @throws ServiceException 服务异常
     */
    public void updateBusyLevelSetting(long shopId, Map<String,String> weekSetting, Map<String,String> dateSetting) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("shopId", shopId);
        params.put("weekSetting", weekSetting);
        params.put("dateSetting", dateSetting);
        call("eleme.shop.updateBusyLevelSetting", params);
    }

    /**
     * 获取店铺营业时间预设置
     *
     * @param shopId 店铺id
     * @return 店铺营业时间预设置
     * @throws ServiceException 服务异常
     */
    public OShopBusyLevelSetting getBusyLevelSetting(long shopId) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("shopId", shopId);
        return call("eleme.shop.getBusyLevelSetting", params);
    }

    /**
     * 设置品牌排序权重
     *
     * @param shopId 店铺Id
     * @param weight 权重值(取值范围[0~10])
     * @throws ServiceException 服务异常
     */
    public void setBrandRankWeight(long shopId, double weight) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("shopId", shopId);
        params.put("weight", weight);
        call("eleme.shop.setBrandRankWeight", params);
    }

    /**
     * 获取店铺可补贴配送费的标品及补贴上限
     *
     * @param shopId 店铺Id
     * @return 店铺可补贴配送费的标品及补贴上限集合
     * @throws ServiceException 服务异常
     */
    public List<ProductInfoForPromotion> getProductSubsidyLimit(long shopId) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("shopId", shopId);
        return call("eleme.shop.getProductSubsidyLimit", params);
    }

    /**
     * 设置店铺T模型
     *
     * @param shopId 店铺Id
     * @param deliveryTime 配送总时间(单位:分钟)
     * @throws ServiceException 服务异常
     */
    public void setShopTModel(long shopId, Integer deliveryTime) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("shopId", shopId);
        params.put("deliveryTime", deliveryTime);
        call("eleme.shop.setShopTModel", params);
    }

    /**
     * 设置店铺假期歇业
     *
     * @param shopId 店铺Id
     * @param vocationDates  店铺休假日期
     * @param enabled  店铺休假是否有效
     * @throws ServiceException 服务异常
     */
    public void setShopVocations(long shopId, List<String> vocationDates, Boolean enabled) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("shopId", shopId);
        params.put("vocationDates", vocationDates);
        params.put("enabled", enabled);
        call("eleme.shop.setShopVocations", params);
    }

    /**
     * 获取店铺有效的假期歇业日期
     *
     * @param shopId 店铺Id
     * @return 返回店铺有效的假期歇业日期list |["2018-11-05:2018-11-06","2018-11-09:2018-11-11"]
     * @throws ServiceException 服务异常
     */
    public List<String> getShopVocation(long shopId) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("shopId", shopId);
        return call("eleme.shop.getShopVocation", params);
    }

    /**
     * 提交开店申请接口
     *
     * @param openStoreMessage 开店申请表单
     * @return 请求提交id
     * @throws ServiceException 服务异常
     */
    public Long submitOpenStoreMessageAudit(OpenStoreMessageBody openStoreMessage) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("openStoreMessage", openStoreMessage);
        return call("eleme.shop.setup.submitOpenStoreMessageAudit", params);
    }

    /**
     * 星巴克提交开店申请接口
     *
     * @param openStoreMessage 开店申请表单
     * @return 请求提交id
     * @throws ServiceException 服务异常
     */
    public Long submitOpenStoreForMermaid(OpenStoreMessageBody openStoreMessage) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("openStoreMessage", openStoreMessage);
        return call("eleme.shop.setup.submitOpenStoreForMermaid", params);
    }

    /**
     * 更新申请信息接口
     *
     * @param updateStoreMessageBody 开店申请表单
     * @throws ServiceException 服务异常
     */
    public void updateOpenStoreMessageAudit(UpdateStoreMessageBody updateStoreMessageBody) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("updateStoreMessageBody", updateStoreMessageBody);
        call("eleme.shop.setup.updateOpenStoreMessageAudit", params);
    }

    /**
     * 查询请求状态接口
     *
     * @param submitId 请求提交id
     * @return 流程状态返回体
     * @throws ServiceException 服务异常
     */
    public ProcessStatusResult queryProcessStatusBySubmitId(Long submitId) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("submitId", submitId);
        return call("eleme.shop.setup.queryProcessStatusBySubmitId", params);
    }

    /**
     * 图片上传处理接口（5M以内图片）
     *
     * @param imageBase64 base64字节流
     * @return 图片处理后的hash值
     * @throws ServiceException 服务异常
     */
    public String uploadImage(String imageBase64) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("imageBase64", imageBase64);
        return call("eleme.shop.setup.uploadImage", params);
    }

    /**
     * 图片上传处理接口（500K以内图片）
     *
     * @param imageBase64 base64字节流
     * @return 图片处理后的hash值
     * @throws ServiceException 服务异常
     */
    public String uploadMinImage(String imageBase64) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("imageBase64", imageBase64);
        return call("eleme.shop.setup.uploadMinImage", params);
    }

    /**
     * 远程上传图片接口
     *
     * @param url 图片url
     * @return 图片处理后的hash值
     * @throws ServiceException 服务异常
     */
    public String uploadImageWithRemoteUrl(String url) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("url", url);
        return call("eleme.shop.setup.uploadImageWithRemoteUrl", params);
    }
}
